<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" href="../../css/aui.css">
		<link rel="stylesheet" href="../../css/aliance.css">
		<link rel="stylesheet" href="../../css/index.css">
		<link rel="stylesheet" href="../../css/pulice.css">
		<link rel="stylesheet" type="text/css" href="../../css/allindex.css" />
		<script src="../../js/api.js"></script>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/libs/swiper.min.js"></script>
		<script src="../../js/vue.min.js"></script>
		<script src="../../js/vue-resource.min.js"></script>
		<script src="../../js/aui-toast.js"></script>
		<script src="../../js/common.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.8&key=1541c9a07778b4a05f644ce5f37391aa&plugin=AMap.Geocoder"></script>
		<script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
		<script>
			setToken();
			$(function() {
				var app = new Vue({
					el: '#app',
					data: {
						goods: [],
						fenlei: [],
						storePos2: []
					},
					mounted: function() {
						this.$nextTick(function() {
							this.myFenLei();
						})
					},
					methods: {
						myFenLei: function() {
							this.$http.get(SURL + "app/site/industry", {
								params: {
									"type": 1
								}
							}).then(function(res) {
								console.log(res.body.data)
								this.fenlei = res.body.data;
							}).catch(function(req) {

							});

						},
						go_detail: function(id, Name) { //方法
							if(id != 10086) {
								location.href = "allDetails.html?hyId=" + id + '&hyName=' + Name;
							} else {
								location.href = "more.html";
							}

						},
						go_details: function(id) { //方法
								location.href = "details.html?shopId=" + id;

						},

					}
				});

				$('.footer').load('../../data/footer.html');

				var map, geolocation;
				//加载地图，调用浏览器定位服务
				map = new AMap.Map('container', {
					resizeEnable: true,
					zoom: 18
				});
				map.plugin('AMap.Geolocation', function() {
					geolocation = new AMap.Geolocation({
						enableHighAccuracy: true, //是否使用高精度定位，默认:true
						timeout: 10000, //超过10秒后停止定位，默认：无穷大
						buttonOffset: new AMap.Pixel(10, 30), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
						zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
						buttonPosition: 'RB'
					});
					map.addControl(geolocation);
					geolocation.getCurrentPosition();
					AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
					AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
				});
				map.plugin("AMap.CitySearch", function() {
			        //实例化城市查询类
			        var citysearch = new AMap.CitySearch();
					console.log(citysearch)
			        //自动获取用户IP，返回当前城市
			        citysearch.getLocalCity();
			        AMap.event.addListener(citysearch, "complete", function(result){
			            if(result && result.city && result.bounds) {
			                var cityinfo = result.city;
			                var citybounds = result.bounds;
			                console.log(cityinfo);
			                $('#result').text(cityinfo);
//			                document.getElementById('result').innerHTML = "您当前所在城市："+cityinfo+"";
			                //地图显示当前城市
//			                map.setBounds(citybounds);
			            }
			            else {
//			                alert("您当前所在城市："+result.info+"");
			            }
			        });
			        AMap.event.addListener(citysearch, "error", function(result){alert(result.info);});
			    });
				//解析定位结果
				var Jing = [];
				var Wei = [];
				var Zong = [];
				var storePos = [];

				function onComplete(data) {
					Jing.push(data.position.getLng());
					Wei.push(data.position.getLat());
					Zong.push(data.position.getLng(), data.position.getLat());
					console.log(Jing);
					console.log(Wei);
					console.log(Zong)
					$.get(SURL + 'app/shops/storePos', {
						"lng": Jing[0],
						"lat": Wei[0],
						"shopName": "",
						"industry": '1'
					}, function(res) {
						console.log(res)
						for(var i = 0; i < res.data.length; i++) {
							app.storePos2.push(res.data[i]);
						}
					})

				}
				//解析定位错误信息
				function onError(data) {
					alert('定位失败');
				}

				$('.hm-center-left').click(function() {
					$('.hm-center-right').removeClass('hm-center-active');
					$(this).addClass('hm-center-active');
					$('#container').css('display', 'none');
					$('#app').css('display', 'block');

				})
				$('.hm-center-right').click(function() {
					$('.hm-center-left').removeClass('hm-center-active');
					$(this).addClass('hm-center-active');
					$('#container').css('display', 'block');
					$('#app').css('display', 'none');
				})

			})
		</script>

		<title>联盟商家</title>
	</head>

	<body onload="regeocoder()">
		<div class="hm-Bar">
			<div class="hm-Map">
				<div class="hm-Map-left" id="result">
					石家庄市
				</div>
				<div class="hm-Map-center">
					<div class="hm-center-left hm-center-active">列表</div>
					<div class="hm-center-right">地图</div>
				</div>
				<div class="hm-Map-right">
					<a href="allsearch.html"><img src="../../img/sreachIconWhite.png" /> </a>
				</div>
			</div>
		</div>
		<div id="app">
			<!--导航-->
			<div class="aui-grid aui-margin-b-15">
				<div class="aui-row">
					<div class="aui-col-xs-3" v-for="(v,i) in fenlei" @click="go_detail(v.hyId,v.hyName)">
						<div class="img-size">
							<img :src="imgUrl + v.icon" alt="">
						</div>
						<div class="aui-grid-label">{{v.hyName}}</div>
					</div>
				</div>
			</div>
			<!--中间-->
			<div class="nearby-shops">
				<div class="hmMIn">
					<div class="hmShops">
						<div class="hmDisTit hmShopTit">附近商家</div>
						<ul class="hmShopList">
							<li class="nearby-shop clearFix" v-for="(j,i) in storePos2" @click="go_details(j.shopId)">
								<img class="hmShopImg" :src="imgUrl+j.logo" alt="" />
								<div class="hmShopBox">
									<div class="contTit">
										{{j.shopName}}
									</div>
									<div class="contRate clearFix">
										{{j.address}}
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div>
			</div>

		</div>
		<div id="container"></div>
		<!--<script type="text/javascript">
			mapObj.plugin(["AMap.CitySearch"], function() {
        //实例化城市查询类
        var citysearch = new AMap.CitySearch();
        //自动获取用户IP，返回当前城市
        citysearch.getLocalCity();
        AMap.event.addListener(citysearch, "complete", function(result){
            if(result && result.city && result.bounds) {
                var cityinfo = result.city;
                var citybounds = result.bounds;
                document.getElementById('result').innerHTML = "您当前所在城市："+cityinfo+"";
                //地图显示当前城市
                mapObj.setBounds(citybounds);
            }
            else {
                document.getElementById('result').innerHTML = "您当前所在城市："+result.info+"";
            }
        });
        AMap.event.addListener(citysearch, "error", function(result){alert(result.info);});
    });
	var map = new AMap.Map("container", {
        resizeEnable: true,
		zoom: 18
    }),    
    lnglatXY = [116.396574, 39.992706]; //已知点坐标
    function regeocoder() {  //逆地理编码
        var geocoder = new AMap.Geocoder({
            radius: 1000,
            extensions: "all"
        });        
        geocoder.getAddress(lnglatXY, function(status, result) {
            if (status === 'complete' && result.info === 'OK') {
                geocoder_CallBack(result);
            }
        });        
        var marker = new AMap.Marker({  //加点
            map: map,
            position: lnglatXY
        });
        map.setFitView();
    }
    function geocoder_CallBack(data) {
        var address = data.regeocode.formattedAddress; //返回地址描述
        document.getElementById("result").innerHTML = address;
    }
</script>-->
		<!--页尾-->
	</body>

</html>